package cn.brucemaa.spring_ai_demo.controller;

import com.alibaba.cloud.ai.dashscope.api.DashScopeApi;
import com.alibaba.cloud.ai.dashscope.chat.DashScopeChatModel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.rag.preretrieval.query.transformation.CompressionQueryTransformer;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping(path = "/chat")
public class ChatController {

    @PostMapping(path = "/completions")
    public void completions(String message) {
        var apiKey = "sk-eb8cd962b7fe4930ad380d74ff24e6bc";
        // 请求信息中，要包含，或者能获取到模型基本信息，和配置信息
        var dashScopeApi = new DashScopeApi(apiKey);
        var chatModel = new DashScopeChatModel(dashScopeApi);
        var chatClient = ChatClient.builder(chatModel).build();
        // 压缩
        //CompressionQueryTransformer.builder().chatClientBuilder(chatClient).build();
        //chatClient.prompt()
        //        .options(options -> {})
        //        .advisors()
        //        .tools("toolNames")
        //        .system("system")
        //        .user("user")
        //        .messages()
        //        .call();
    }
}
